package spring.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import spring.service.DemoService;

@Controller
public class HomeController {
    //添加一个日志器
    private static final Logger logger = LoggerFactory.getLogger(HomeController.class);

    @Autowired
    DemoService demoService;

    //映射一个action
    @GetMapping("/index")
    public  String index(Model model){
        //输出日志文件
        logger.info("the first jsp pages");
        //返回一个index.jsp这个视图
        model.addAttribute("msg", demoService.saySomething());

        return "index";
    }

    @GetMapping("testRest")
    @ResponseBody
    public String testRest() {
        return demoService.saySomething();
    }
}